package presentacion;

import io.OntologyManager;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.table.DefaultTableModel;
import logica.ItemLista;
import logica.OrdenDeMerito;

/**
 * Ventana principal de la aplicación. Contiene todos los datos de una Beca de ayuda económica
 * y de un concurso para dicha Beca.
 * 
 * @author Administrador
 */
public class Ventana extends javax.swing.JFrame {

    private OntologyManager ontManager;
    private DefaultListModel modeloInscriptos;
    private DefaultListModel modeloPostulantes;
    private DefaultTableModel modeloTablaMerito;
    private DefaultTableModel modeloTablaPreRequisitos;
    private DefaultTableModel modeloTablaRequisitos;
    
    /** Creates new form Ventana */
    public Ventana() {
        initComponents();
        modeloInscriptos= new DefaultListModel();
        listaInscriptos.setModel(modeloInscriptos);
        modeloPostulantes= new DefaultListModel();
        listaPostulantes.setModel(modeloPostulantes);
        modeloTablaMerito= (DefaultTableModel) tablaOrdenMerito.getModel();
        modeloTablaPreRequisitos= (DefaultTableModel) tablaPrerequisitos.getModel();
        modeloTablaRequisitos= (DefaultTableModel) tablaRequisitos.getModel();
        this.setOntologia();
    }
    
    //Método llamado desde el Main para iniciar la aplicación.
    public void iniciar()
    {
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        DialogoSeleccionarBeca dsb= new DialogoSeleccionarBeca(ontManager);
        String [] retorno= dsb.hacerVisible(this);
        if (retorno == null)
            this.salir(null);
        else
            this.cargarPanel(retorno[0], retorno[1]);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        nombreConcurso = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaInscriptos = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaPostulantes = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tablaOrdenMerito = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tablaRequisitos = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        numero = new javax.swing.JLabel();
        fechaInicio = new javax.swing.JLabel();
        fechaFin = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        estadoConcurso = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        becario = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tablaPrerequisitos = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        nombreBeca = new javax.swing.JLabel();
        beneficio = new javax.swing.JLabel();
        estadoBeca = new javax.swing.JLabel();
        tipo = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        cargaHoraria = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Ontologías");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                cruzVentana(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos del Concurso", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 8))); // NOI18N

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Nombre:");

        nombreConcurso.setText("(ninguno)");

        jLabel2.setText("Inscriptos:");

        listaInscriptos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaInscriptos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                inscriptosMouse(evt);
            }
        });
        listaInscriptos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                inscriptosKey(evt);
            }
        });
        jScrollPane1.setViewportView(listaInscriptos);

        listaPostulantes.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaPostulantes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                postulantesMouse(evt);
            }
        });
        listaPostulantes.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                postulantesKey(evt);
            }
        });
        jScrollPane2.setViewportView(listaPostulantes);

        jLabel3.setText("Postulantes:");

        tablaOrdenMerito.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Postulante", "Puntaje"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tablaOrdenMerito);

        jLabel4.setText("Orden de mérito:");

        tablaRequisitos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Requisito", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(tablaRequisitos);

        jLabel5.setText("Requisitos:");

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Número:");

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Fecha de inicio:");

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Fecha de cierre:");

        numero.setText("(ninguno)");

        fechaInicio.setText("(ninguno)");

        fechaFin.setText("(ninguno)");

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel14.setText("Estado:");

        estadoConcurso.setText("(ninguno)");

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel16.setText("Becario:");

        becario.setFont(new java.awt.Font("Tahoma", 1, 11));
        becario.setText("(ninguno)");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
                    .addComponent(jLabel5)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                            .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                            .addComponent(jLabel16, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nombreConcurso, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                            .addComponent(numero, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                            .addComponent(fechaInicio, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                            .addComponent(fechaFin, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                            .addComponent(estadoConcurso, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                            .addComponent(becario, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(nombreConcurso, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(fechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(fechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(estadoConcurso, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(becario)))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos de la Beca", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 8))); // NOI18N

        tablaPrerequisitos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Pre-requisito", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane5.setViewportView(tablaPrerequisitos);

        jLabel9.setText("Pre-Requisitos:");

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Nombre:");

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("Beneficio:");

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText("Estado:");

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText("Tipo:");

        nombreBeca.setText("(ninguno)");

        beneficio.setText("(ninguno)");

        estadoBeca.setText("(ninguno)");

        tipo.setText("(ninguno)");

        jLabel15.setText("Carga horaria:");

        cargaHoraria.setText("(ninguno)");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(estadoBeca, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
                    .addComponent(beneficio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(nombreBeca, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cargaHoraria, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tipo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(nombreBeca, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(beneficio, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(estadoBeca, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(cargaHoraria))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(tipo, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane5, 0, 0, Short.MAX_VALUE)))
        );

        jMenu1.setText("Archivo");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Seleccionar Beca...");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seleccionarBeca(evt);
            }
        });
        jMenu1.add(jMenuItem1);
        jMenu1.add(jSeparator1);

        jMenuItem2.setText("Salir");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salir(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Grupo");

        jMenuItem3.setText("Acerca de...");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acercaDe(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //Evento de la barra de menú que abre un diálogo para cambiar de Beca y concurso abiertos.
    private void seleccionarBeca(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seleccionarBeca
        DialogoSeleccionarBeca dsb= new DialogoSeleccionarBeca(ontManager);
        String [] retorno= dsb.hacerVisible(this);
        if (retorno == null)
            this.salir(null);
        else
            this.cargarPanel(retorno[0], retorno[1]);
    }//GEN-LAST:event_seleccionarBeca

    //Evento de la barra de menú que cierra la aplicación.
    private void salir(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salir
        ontManager.cerrar();
        System.exit(0);
    }//GEN-LAST:event_salir

    //Evento para cerrar la aplicación.
    private void cruzVentana(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_cruzVentana
        this.salir(null);
    }//GEN-LAST:event_cruzVentana

    //Este evento maneja el doble click sobre la lista de inscriptos, abriendo un diálogo
    //que muestra todos los datos del alumno seleccionado.
    private void inscriptosMouse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_inscriptosMouse
        if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2)
        {
            String nombreAlumno= (String) listaInscriptos.getSelectedValue();
            if (nombreAlumno != null)
                this.abrirPanelAlumno(nombreAlumno);
        }
    }//GEN-LAST:event_inscriptosMouse

    //Este evento abre el diálogo que muestra todos los datos del alumno seleccionado sobre
    //la lista de inscriptos y sobre el cual se presionó la tecla Enter.
    private void inscriptosKey(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inscriptosKey
        if (evt.getKeyCode() == KeyEvent.VK_ENTER)
        {
            String nombreAlumno= (String) listaInscriptos.getSelectedValue();
            if (nombreAlumno != null)
                this.abrirPanelAlumno(nombreAlumno);
        }
    }//GEN-LAST:event_inscriptosKey

    //Este evento maneja el doble click sobre la lista de postulantes, abriendo un diálogo
    //que muestra todos los datos del alumno seleccionado.
    private void postulantesMouse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_postulantesMouse
        if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2)
        {
            String nombreAlumno= (String) listaPostulantes.getSelectedValue();
            if (nombreAlumno != null)
                this.abrirPanelAlumno(nombreAlumno);
        }
    }//GEN-LAST:event_postulantesMouse

    //Este evento abre el diálogo que muestra todos los datos del alumno seleccionado sobre
    //la lista de postulantes y sobre el cual se presionó la tecla Enter.
    private void postulantesKey(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_postulantesKey
        if (evt.getKeyCode() == KeyEvent.VK_ENTER)
        {
            String nombreAlumno= (String) listaPostulantes.getSelectedValue();
            if (nombreAlumno != null)
                this.abrirPanelAlumno(nombreAlumno);
        }
    }//GEN-LAST:event_postulantesKey

    //Evento de la barra de menú que abre un diálogo informativo sobre el grupo que desarrollo
    //este trabajo.
    private void acercaDe(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acercaDe
        DialogoAcercaDe dad= new DialogoAcercaDe();
        dad.hacerVisible(this);
    }//GEN-LAST:event_acercaDe

    /**
     * Se crea una instancia del controlador de la ontología.
     */
    private void setOntologia()
    {
        ontManager= new OntologyManager("file:///" + System.getProperty("user.dir") + "/ontologia/TPFinal.owl",
                "http://www.semanticweb.org/ontologies/2012/10/Ontology1353709240214.owl#");
    }
    
    /**
     * Carga el panel contenido en esta ventana con los datos correspondientes a la Beca
     * y a el concurso seleccionados.
     * 
     * @param nombreBeca nombre de la Beca seleccionada por el usuario.
     * @param nombreConcurso nombre del concurso seleccionado por el usuario.
     */
    private void cargarPanel(String nombreBeca, String nombreConcurso)
    {
        this.nombreBeca.setText(nombreBeca);
        this.beneficio.setText(ontManager.getDataPropertyValue("Beca", nombreBeca, "beneficioAyudaEconomica"));
        this.estadoBeca.setText(ontManager.getDataPropertyValue("Beca", nombreBeca, "estadoBeca"));
        this.tipo.setText(ontManager.getDataPropertyValue("Beca", nombreBeca, "tipoAyudaEconomica"));
        this.cargaHoraria.setText(ontManager.getDataPropertyValue("Beca", nombreBeca, "cargaHoraria"));
        this.nombreConcurso.setText(nombreConcurso);
        this.numero.setText(ontManager.getDataPropertyValue("Concurso", nombreConcurso, "numero"));
        this.fechaInicio.setText(this.acomodarFecha(ontManager.getDataPropertyValue("Concurso", nombreConcurso, "fechaInicio")));
        this.fechaFin.setText(this.acomodarFecha(ontManager.getDataPropertyValue("Concurso", nombreConcurso, "fechaFin")));
        this.estadoConcurso.setText(ontManager.getDataPropertyValue("Concurso", nombreConcurso, "estadoConcurso"));
        this.cargarInscriptos(nombreConcurso);
        this.cargarRequisitos(nombreConcurso);
        this.cargarPreRequisitos(nombreBeca);
        List<String> postulantes= this.cargarPostulantes(nombreConcurso);
        List<ItemLista> il= this.cargarOrdenDeMerito(postulantes);
        if (il == null)
            this.becario.setText("(ninguno)");
        else 
        {
            if (il.size() == 1)
            {
                ontManager.setPrimeroOrdenMeritoTrue(il.get(0).getNombrePostulante());
                this.becario.setText(ontManager.getBecario(nombreConcurso));
            }
            else
            {
                if (ontManager.poseeBecario(nombreConcurso))
                    this.becario.setText(ontManager.getBecario(nombreConcurso));
                else
                {
                    DialogoEmpates de= new DialogoEmpates(il);
                    String seleccionado= de.hacerVisible(this);
                    ontManager.setPrimeroOrdenMeritoTrue(seleccionado);
                    this.becario.setText(ontManager.getBecario(nombreConcurso));
                }
            }
        }
    }
    
    /**
     * Cambia el formato de la fecha del tipo aaaa/mm/dd a dd/mm/aaaa.
     * 
     * @param unaFecha String a ser modificado.
     * @return un String con el formato deseado.
     */
    private String acomodarFecha(String unaFecha)
    {
        if (unaFecha.isEmpty())
            return "";
        String [] partes= unaFecha.split("-");
        return partes[2] + "/" + partes[1] + "/" + partes[0];
    }
    
    /**
     * Hace visible el diálogo que contiene todos los datos de un alumno.
     * 
     * @param nombre individuo del cual se obtendrán sus datos en la ontología.
     */
    private void abrirPanelAlumno(String nombre)
    {
        DialogoAlumno da= new DialogoAlumno(ontManager, nombre);
        da.hacerVisible(this);
    }
    
    /**
     * Carga la lista de inscriptos a un concurso.
     * 
     * @param nombreConcurso concurso del cual se obtendrá la información.
     */
    private void cargarInscriptos(String nombreConcurso)
    {
        List<String> inscriptos= ontManager.getInscriptos(nombreConcurso);
        modeloInscriptos.removeAllElements();
        for (String s : inscriptos)
            modeloInscriptos.addElement(s);
    }
    
    /**
     * Carga la lista de postulantes a un concurso.
     * 
     * @param nombreConcurso concurso del cual se obtendrá la información.
     */
    private List<String> cargarPostulantes(String nombreConcurso)
    {
        List<String> postulantes= ontManager.getPostulantes(nombreConcurso);
        modeloPostulantes.removeAllElements();
        for (String s : postulantes)
            modeloPostulantes.addElement(s);
        return postulantes;
    }
    
    /**
     * Carga la tabla de orden de mérito con el nombre del postulante y su respectivo puntaje,
     * ordenado de mayor a menor en base a dichos puntajes.
     * 
     * @param postulantes lista con los postulantes a un concurso.
     * @return una lista con los postulantes que empataron en el concurso o null si no hay postulantes.
     */
    private List<ItemLista> cargarOrdenDeMerito(List<String> postulantes)
    {
        OrdenDeMerito odm= new OrdenDeMerito();
        List<ItemLista> empates= new ArrayList<ItemLista>();
        for (String post : postulantes)
        {
            String puntaje= ontManager.getDataPropertyValue("Postulante", post, "puntaje");
            ItemLista il= new ItemLista(post, Float.parseFloat(puntaje));
            odm.insertar(il);
        }
        List<ItemLista> lista= odm.getLista();
        this.vaciarTabla(modeloTablaMerito);
        for (ItemLista i : lista)
        {
            String [] fila= new String[2];
            fila[0]= i.getNombrePostulante();
            fila[1]= String.valueOf(i.getPuntaje());
            modeloTablaMerito.addRow(fila);
        }
        if (lista.isEmpty())
            return null;
        float maximoPuntaje= lista.get(0).getPuntaje();
        for (ItemLista i : lista)
        {
            if (i.getPuntaje() == maximoPuntaje)
                empates.add(i);
        }
        return empates;
    }
    
    /**
     * Vacía la tabla pasada como parámetro.
     * 
     * @param dtm modelo de la tabla a ser vaciada.
     */
    private void vaciarTabla(DefaultTableModel dtm) {
        while (dtm.getRowCount() > 0)
            dtm.removeRow(0);
    }
    
    /**
     * Carga la tabla de pre-requisitos para una Beca.
     * 
     * @param nombreBeca Beca de la cual se obtendrán los datos.
     */
    private void cargarPreRequisitos(String nombreBeca)
    {
        List<String []> preRequisitos= ontManager.getPreRequisitos(nombreBeca);
        this.vaciarTabla(modeloTablaPreRequisitos);
        for (String [] s : preRequisitos)
            modeloTablaPreRequisitos.addRow(s);
    }
    
    /**
     * Carga la tabla de requisitos para un concurso.
     * 
     * @param nombreConcurso concurso del cual se obtendrán los datos.
     */
    private void cargarRequisitos(String nombreConcurso)
    {
        List<String []> requisitos= ontManager.getRequisitos(nombreConcurso);
        this.vaciarTabla(modeloTablaRequisitos);
        for (String [] s : requisitos)
            modeloTablaRequisitos.addRow(s);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel becario;
    private javax.swing.JLabel beneficio;
    private javax.swing.JLabel cargaHoraria;
    private javax.swing.JLabel estadoBeca;
    private javax.swing.JLabel estadoConcurso;
    private javax.swing.JLabel fechaFin;
    private javax.swing.JLabel fechaInicio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JList listaInscriptos;
    private javax.swing.JList listaPostulantes;
    private javax.swing.JLabel nombreBeca;
    private javax.swing.JLabel nombreConcurso;
    private javax.swing.JLabel numero;
    private javax.swing.JTable tablaOrdenMerito;
    private javax.swing.JTable tablaPrerequisitos;
    private javax.swing.JTable tablaRequisitos;
    private javax.swing.JLabel tipo;
    // End of variables declaration//GEN-END:variables
}
